#include "db/datasegment.hxx"
#include "util/serialize.hxx"
#include "util/logger.hxx"


uint64_t DataSegmentHeader::MAGIC = 0x9876565430891242;
uint32_t DataSegmentHeader::DATASEGMENT_HEADER_LENGTH = 1024;

DataSegmentHeader::DataSegmentHeader() {

    m_version = 0;
    m_magic = MAGIC;
}



std::string DataSegmentHeader::serialize() {

    StringSerializer ser;

    ser.appendLong(m_version);
    ser.appendLong(m_magic);

    return ser.str();
}


void DataSegmentHeader::deserialize(const std::string& data) {
    
    Deserializer des(data);

    m_version = des.readLong();
    m_magic = des.readLong();
}


std::string DataSegmentHeader::toString() {
   
    InfoSerializer  ser;

    ser.appendLong("version", m_version);
    ser.appendLong("magic", m_magic);

    return ser.str();
}


DataSegment::DataSegment(uint32_t segId, const std::string& partitionPath, uint32_t capacity) 
: m_segid(segId), 
  m_capacity(capacity), 
  m_partitionPath(partitionPath),
  m_dataSize(0),
  m_alive(true),
  m_segMode(READ_ONLY) {

}
